import QQMap from '../../../utils/qqmap'
import Dialog from '@vant/weapp/dialog/dialog';
Page({
  data: {
    dialogVisible: false,
    houseList: [],
  },
  async onLoad(){
   
  },
  onShow(){
    this.getHouseList()
  },
  async getHouseList(){
    const res = await wx.http.get('/room')
    this.setData({
      houseList: res.data
    })
  },
  // 删除功能
  async swipeClose(ev) {
    const { position, instance } = ev.detail
    // console.log("ev",ev);
    const id = ev.mark.id
    // 关闭实例
    instance.close()
    if (position === 'right') {
      // 显示 Dialog 对话框
      try {
        await Dialog.confirm({
          message: '是否删除已绑定房屋',
        })
      } catch (error) {
        //不处理
        // console.log(error);
        wx.utils.toast("取消删除")
        return
      }
      await wx.http({
        method: 'DELETE',
        url: '/room/' + id
      })
      wx.utils.toast("删除成功")
      // 重新加载数据
      this.getHouseList()
      // swiper-cell 滑块关闭
      // instance.close()
    }
  },
// 跳转页面
  goDetail(ev) {
    // console.log(ev);
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id='+ ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
